﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


namespace PRE
{
    public partial class FrmMain : RibbonForm
    {
        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static WS.UTL.Session _sss = new WS.UTL.Session();

        public FrmMain()
        {
            InitializeComponent();
            InitSkinGallery();
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            bbiDangnhap_ItemClick(sender, null);
        }

        private void EnableMenu()
        {
            switch (_sss.Role)
            {
                case WS.UTL.Session.Roles.Admin:

                    break;

                case WS.UTL.Session.Roles.Manager:
                    bbiThanhvien.Visibility = BarItemVisibility.Never;
                    
                    break;

                case WS.UTL.Session.Roles.User:
                    bbiDSSV.Visibility = BarItemVisibility.Never;
                    bbiThanhvien.Visibility = BarItemVisibility.Never;

                    break;

                default:
                    break;
            }
        }

        #region Trang chủ

        private void bbiDangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (bbiDangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                bbiDangnhap.Caption = STR_LOGIN;

                bbiDongtatca_ItemClick(sender, e);
            }

            Login.FrmLogin x = new Login.FrmLogin();
            x.ShowDialog();

            if (_sss.Login)
            {
                bsiUser.Caption = _sss.Name;
                bbiDangnhap.Caption = STR_LOGOUT;

                rpThongke.Visible = true;
                rpDanhmuc.Visible = true;
            }
            else
            {
                rpDanhmuc.Visible = false;
                rpThongke.Visible = false;
            }

            EnableMenu();
        }

        private void bbiDongtatca_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();
        }

        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        #endregion

        #region Danh mục

        private void bbiSinhvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmSinhvien) return;
            var frm = new Catalog.FrmSinhvien() { MdiParent = this };

            frm.Show();
        }

        private void bbiLophoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmLophoc) return;
            var frm = new Catalog.FrmLophoc() { MdiParent = this };

            frm.Show();
        }

        private void bbiThanhvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmThanhvien) return;
            var frm = new Catalog.FrmThanhvien() { MdiParent = this };

            frm.Show();
        }


        #endregion

        #region Thống kê

        private void bbiDSSV_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Report.FrmDSSV) return;
            var frm = new Report.FrmDSSV() { MdiParent = this };

            frm.Show();
        }

        #endregion

        

        
    }
}